package com.blog.admin.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.blog.admin.config.OssConfiguration;
import com.blog.admin.service.FileInfoService;
import com.blog.admin.service.PhotoService;
import com.blog.admin.service.SiteConfigService;
import com.blog.common.core.domain.R;
import com.blog.common.core.web.domain.AjaxResult;
import com.blog.common.domain.entity.FileInfo;
import com.blog.common.domain.entity.Photo;
import com.blog.common.domain.entity.PhotoAlbum;
import com.blog.common.domain.entity.SiteConfig;
import com.blog.system.api.feign.RemoteConfigService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 配置控制器
 * </p>
 *
 * @author Valerie
 * @date 2023/4/15
 **/
@RestController
@AllArgsConstructor
public class SiteController {

    private final SiteConfigService siteConfigService;


    private final RemoteConfigService remoteConfigService;

    /**
     * 获取网站配置
     *
     * @return {@link R<String>}
     */
    @GetMapping("/website/config")
    @ApiOperation("获取网站配置")
    public R<SiteConfig> getSiteConfig(){
        return R.ok(siteConfigService.getSiteConfig());
    }


    /**
     * 获取网站主页图片
     *
     * @return {@link AjaxResult}
     */
    @PutMapping("/website/pageCover")
    @ApiOperation("获取网站主页图片")
    public R<Void> saveSitePageCover(){
        siteConfigService.savePageCover();
        return R.ok();
    }


    /**
     * 设置网站主页图片
     *
     * @param methodType 方式
     * @return {@link AjaxResult}
     */
    @GetMapping("/website/pageCover")
    @ApiOperation("设置网站主页图片")
    public AjaxResult setSitePageCover(@RequestParam("methodType") Serializable methodType){
        siteConfigService.setSitePageCover(methodType);
        return AjaxResult.success();
    }


    /**
     * 设置其他页面壁纸
     *
     * @param methodType 方式
     * @return {@link AjaxResult}
     */
//    @GetMapping("/website/anotherPageCover")
    private AjaxResult setAnotherPageCover(@RequestParam("methodType") Serializable methodType){
        siteConfigService.setSiteAnotherPageCover(methodType);
        return AjaxResult.success();
    }
}
